# coding:utf8
"""
author:shadu@foxmail.com
"""

import urllib2

TIMEOUT = 20

# warnings.filterwarnings("ignore")
# import requests
# requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL'

HTTP_TIMEOUT_SECONDS = 15
HTTP_HEADER_ACCEPT = 'text/html, application/json, text/javascript, */*; q=0.01'
HTTP_HEADER_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 '\
                 '(KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'


HTTP_HEADERS = {
    'Accept': HTTP_HEADER_ACCEPT,
    'User-Agent': HTTP_HEADER_UA,
}


def get_html_safely(url, default='-'):
    text = default
    try:
        req = urllib2.Request(url, headers=HTTP_HEADERS)
        res = urllib2.urlopen(req, timeout=TIMEOUT)
        text = res.read()
    except Exception, e:
        print e
    return text


if __name__ == '__main__':
    print get_html_safely('https://www.example.com/')
